<?php
// +----------------------------------------------------------------------
// | OneKeyAdmin [ Believe that you can do better ]
// +----------------------------------------------------------------------
// | Copyright (c) 2020-2023 http://onekeyadmin.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: MUKE <513038996@qq.com>
// +----------------------------------------------------------------------
namespace plugins\alisms\admin\controller;

use think\facade\View;
use app\admin\BaseController;
use plugins\alisms\addons\AliSms;
use app\admin\model\Config as ConfigModel;
/**
 * 配置
 */
class Config extends BaseController
{
    public function index()
    {
        $name = 'app_alisms';
        if ($this->request->isPost()) {
            $msg = ConfigModel::setVal($name, '阿里云短信', input('post.value'));
            return json($msg);
        } else {
            $config = ConfigModel::getVal($name);
            if (! $config) {
                $config = [
                    'accessKeyId'      => "",
                    'accessKeySecret'  => "",
                    'template'         => [
                        ["id" => "26BEKytK3bCe","signName" => "OneKeyAdmin短信验证码","templateCode" => "SMS_235480739"]
                    ],
                ];
            }
            View::assign('config', $config);
            return View::fetch();
        }
    }

    public function test()
    {
        if ($this->request->isPost()) {
            $input  = input('post.');
            $result = AliSms::send($input['templateId'], $input['phone'], json_decode($input['content'], true));
            return json($result);
        }
    }
}